package com.fwh.web.controller;

import com.baomidou.mybatisplus.entity.Column;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.fwh.web.eneity.TbInterfaceRecord;
import com.fwh.web.service.ITbInterfaceRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 发起人 前端控制器
 * </p>
 *
 * @author fwh
 * @since 2019-04-11
 */
@Controller
@RequestMapping("/tbInterfaceRecord")
@Slf4j
public class TbInterfaceRecordController {
    //此处使用slf4j注解.
//    Log log = LogFactory.get(TbInterfaceRecordController.class);
    @Autowired
    private ITbInterfaceRecordService tbInterfaceRecordService;
	/**
	 * 测试入库
	 * @param   
	 * @return void  
	 * @author:fwh [2019/4/11 && 14:17]
	 */
	@GetMapping("/testDb")
    public void testDb(){
        TbInterfaceRecord  tbInterfaceRecord = new TbInterfaceRecord();
        tbInterfaceRecord.setBeginTime(new Date());
	    tbInterfaceRecord.setArgInfo("参数");
	    tbInterfaceRecord.setCreateDate(new Date());
	    tbInterfaceRecord.setFailMsg("失败消息");
	    tbInterfaceRecord.setInitiator("发起人");
        boolean insert = tbInterfaceRecordService.insert(tbInterfaceRecord);
        log.info("数据入库结果为:{}",insert);
    }
    /**
     * 查询所有
     * @param   
     * @return void  
     * @author:fwh [2019/4/11 && 15:57]
     */  
    @GetMapping("/queryAll")
    public void queryAll(){
		List<TbInterfaceRecord> tbInterfaceRecordList = tbInterfaceRecordService.queryAll();
		EntityWrapper<TbInterfaceRecord> wrapper = new EntityWrapper<>();
		wrapper.setSqlSelect(
				new Column().column("region"), new Column().column("region_cn").as("regionCn")
		);
        System.out.println(tbInterfaceRecordService.selectList(wrapper));
        if (null!=tbInterfaceRecordList){
			log.info("数据查询结果为:{}",tbInterfaceRecordList);
		}else {
			log.error("数据查询结果空,id为{}",1);
		}
	}
}
